package work.vcloud.baseinfo.controller;

import work.vcloud.frame.controller.BaseController;
import work.vcloud.frame.dao.OpenDao;
import work.vcloud.frame.vo.OutputVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
@Scope("prototype")
public class RepeatController extends BaseController {

	@Autowired
	OpenDao openDao;

	/**
	 * 教师信息 判断字段重复
	 */
	@RequestMapping("api/teacher.selectRepeatTeacher")
	public OutputVo selectRepeatTeacher() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "teacher.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "teacher.selectPhone");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else if (result2 > 0) {
				return output("4444","手机号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
	
	/**
	 * 专家信息 判断字段重复
	 */
	@RequestMapping("api/expert.selectRepeatExpert")
	public OutputVo selectRepeatExpert() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "expert.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "expert.selectPhone");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result2 > 0) {
				return output("4444","手机号重复","");
			}else if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
	
	/**
	 * 来宾信息 判断字段重复
	 */
	@RequestMapping("api/guest.selectRepeatGuest")
	public OutputVo selectRepeatGuest() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "guest.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "guest.selectPhone");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result2 > 0) {
				return output("4444","手机号重复","");
			}else if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
	
	/**
	 * 学生信息 判断字段重复
	 */
	@RequestMapping("api/student.selectRepeatStudent")
	public OutputVo selectRepeatStudent() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "student.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "student.selectStudentCode");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else if (result2 > 0) {
				return output("4444","学籍号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
	
	
	/**
	 * 家长信息 判断字段重复
	 */
	@RequestMapping("api/parent.selectRepeatParent")
	public OutputVo selectRepeatParent() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "parent.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "parent.selectPhone");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else if (result2 > 0) {
				return output("4444","手机号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
	
	/**
	 * 供应商信息 判断字段重复
	 */
	@RequestMapping("api/company.selectRepeatCompany")
	public OutputVo selectRepeatCompany() throws Exception {
		try {
			Map<String, Object> map = getParameterMap();
			map.remove("page");
			map.put("sqlMapId", "company.selectIdCard");
			Integer result1 = (Integer)openDao.queryForObject(map);
			
			map.put("sqlMapId", "company.selectPhone");
			Integer result2 = (Integer)openDao.queryForObject(map);
			
			if (result1 > 0) {
				return output("4444","身份证件号重复","");
			}else if (result2 > 0) {
				return output("4444","手机号重复","");
			}else {
				return output("0000");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return output("9999");
		}
	}
}
